# Maintainer:
pkgname=libkcapi
pkgver=1.5.0
pkgrel=1
pkgdesc="Linux Kernel Crypto API User Space Interface Library"
url="https://www.chronox.de/libkcapi/index.html"
arch="all"
license="BSD-3-Clause OR GPL-2.0-only"
makedepends="
	autoconf
	automake
	libtool
	linux-headers
	"
checkdepends="bash openssl"
subpackages="$pkgname-dev $pkgname-tools $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/smuellerDD/libkcapi/archive/refs/tags/v$pkgver.tar.gz
	busybox-ln.patch
	"
# requires AF_ALG support and enablement of ktls on running kernel
options="!check"

prepare() {
	default_prepare

	autoreconf -fvi
}

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--prefix=/usr \
		--build=$CBUILD \
		--host=$CHOST \
		--enable-kcapi-hasher \
		--enable-kcapi-speed \
		--enable-kcapi-rngapp \
		--enable-kcapi-encapp \
		--enable-kcapi-dgstapp \
		--enable-kcapi-test \
		--disable-static \
		--disable-werror
	make
}

check() {
	local tests="
		hasher-test.sh
		kcapi-convenience.sh
		kcapi-dgst-test.sh
		kcapi-enc-test-large.sh
		kcapi-enc-test.sh
		kcapi-fuzz-test.sh
		"
	for test in $tests; do
		msg "testing $test"
		./test/$test
	done
}

package() {
	make DESTDIR="$pkgdir" install

	rm "$pkgdir"/usr/lib/.[!.]*
	rm "$pkgdir"/usr/bin/.[!.]*
}

tools() {
	pkgdesc="$pkgdesc (commandline utilities)"

	amove usr/bin
	amove usr/libexec
}

sha512sums="
510d0606cdc9479a77ed07bd3ac59b07c3996402a85cee012e6836d0a31cb06f5b7f715cdb76f3745784aab3154595caec4537b4c774236a139ebfe6e1a8be9b  libkcapi-1.5.0.tar.gz
eb8c14107c1636dc3dcc0db2dc20c2f69ea3fd058c1b3af041926dcf9ce89b0c43219b753aaa8b5aabd8047b75ebee09a1196ac77acc5f6e097309a5a865a87d  busybox-ln.patch
"
